package org.microframework.base.feign.logs.factory;

import org.microframework.base.feign.logs.RemoteLogService;
import org.microframework.base.model.logs.domain.OperationLog;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;

/**
 * 日志服务降级处理
 */
@Component
@Slf4j
public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogService> {

	@Override
	public RemoteLogService create(Throwable throwable) {
		log.error("日志服务调用失败:{}", throwable.getMessage());
		return new RemoteLogService() {

			@Override
			public void recordLoginFailure(String username, String errorMessage, String ip, String location, 
			                              String browser, String os) {
				log.error("记录登录失败日志异常: {}", throwable.getMessage());
			}

			@Override
			public void recordLoginSuccess(String username, String ip, String location, String browser, String os) {
				log.error("记录登录成功日志异常: {}", throwable.getMessage());
			}

			@Override
			public void saveLog(OperationLog operLog, String inner) {
				log.error("保存操作日志异常: {}", throwable.getMessage());
			}
		};
	}
}
